﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ASyncTest
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            await Save();  
            MessageBox.Show("成功的完成写入工作");
        }

        public async  Task Save()
        {
            await Task.Run(() =>
            {
                File.WriteAllText(@"C:\Users\Administrator\Desktop\TEST.txt", "测试一下资源写入情况");
            });
            try
            {
                var result = await new WebClient().DownloadStringTaskAsync("https://gitzab.com");
            }
            catch (Exception)
            {
                MessageBox.Show("服务器链接失败");
            }
            
            

        }
    }
}
